﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pattern_Builder
{
    public class Director
    {
        public void Construct(Builder builder)
        {
            builder.BuildPartA();
            builder.BuildPartB();
        }
    }

    public abstract class Builder
    {
        public abstract void BuildPartA();
        public abstract void BuildPartB();
        public abstract Product getResult();
    }

    public class Builder1 : Builder
    {
        Product product = new Product();

        public override void BuildPartA()
        {
            product.Add("部件A");
        }

        public override void BuildPartB()
        {
            product.Add("部件B");
        }

        public override Product getResult()
        {
            return product;
        }
    }

    public class Builder2 : Builder
    {
        Product product = new Product();

        public override void BuildPartA()
        {
            product.Add("部件X");
        }

        public override void BuildPartB()
        {
            product.Add("部件Y");
        }

        public override Product getResult()
        {
            return product;
        }
    }

    public class Product
    {
        IList<string> parts = new List<string>();

        public void Add(string part)
        {
            parts.Add(part);
        }

        public void Show()
        {
            foreach (string s in parts)
            {
                Console.Write(s + " ");
            }
            Console.WriteLine();
        }
    }
}
